package com.ruoyi.web.controller.safety;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safety.domain.SensorTypeDict;
import com.ruoyi.safety.service.ISensorTypeDictService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传感器类型编码Controller
 * 
 * @author ruoyi
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/safety/sensorTypeDict")
public class SensorTypeDictController extends BaseController
{
    @Autowired
    private ISensorTypeDictService sensorTypeDictService;

    /**
     * 查询传感器类型编码列表
     */
    //@PreAuthorize("@ss.hasPermi('safety:dict:list')")
    @GetMapping("/list")
    @ApiOperation("传感器类型编码")
    public TableDataInfo list(SensorTypeDict sensorTypeDict)
    {
        startPage();
        List<SensorTypeDict> list = sensorTypeDictService.selectSensorTypeDictList(sensorTypeDict);
        return getDataTable(list);
    }

    /**
     * 导出传感器类型编码列表
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:export')")
    @Log(title = "传感器类型编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SensorTypeDict sensorTypeDict)
    {
        List<SensorTypeDict> list = sensorTypeDictService.selectSensorTypeDictList(sensorTypeDict);
        ExcelUtil<SensorTypeDict> util = new ExcelUtil<SensorTypeDict>(SensorTypeDict.class);
        util.exportExcel(response, list, "传感器类型编码数据");
    }

    /**
     * 获取传感器类型编码详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:query')")
    @GetMapping(value = "/{sensorCode}")
    public AjaxResult getInfo(@PathVariable("sensorCode") String sensorCode)
    {
        return success(sensorTypeDictService.selectSensorTypeDictBySensorCode(sensorCode));
    }

    /**
     * 新增传感器类型编码
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:add')")
    @Log(title = "传感器类型编码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SensorTypeDict sensorTypeDict)
    {
        return toAjax(sensorTypeDictService.insertSensorTypeDict(sensorTypeDict));
    }

    /**
     * 修改传感器类型编码
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:edit')")
    @Log(title = "传感器类型编码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SensorTypeDict sensorTypeDict)
    {
        return toAjax(sensorTypeDictService.updateSensorTypeDict(sensorTypeDict));
    }

    /**
     * 删除传感器类型编码
     */
    @PreAuthorize("@ss.hasPermi('safety:dict:remove')")
    @Log(title = "传感器类型编码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sensorCodes}")
    public AjaxResult remove(@PathVariable String[] sensorCodes)
    {
        return toAjax(sensorTypeDictService.deleteSensorTypeDictBySensorCodes(sensorCodes));
    }
}
